package com.hxzy.projectssmplus.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.projectssmplus.dto.HouseHuxingtuDTO;
import com.hxzy.projectssmplus.entity.HouseHuxingtu;
import com.hxzy.projectssmplus.service.HouseHuxingtuService;
import com.hxzy.projectssmplus.vo.AjaxResult;
import com.hxzy.projectssmplus.vo.AjaxTableInfo;
import com.hxzy.projectssmplus.vo.HouseHuxingtuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class HouseHuxingtuController extends BaseController{


    @Autowired
    private HouseHuxingtuService houseHuxingtuService;


    /**
     * 户型图查询
     * @return
     */
    @GetMapping(value = "/house/huxingtu/getData")
    public AjaxTableInfo search(HouseHuxingtuDTO houseHuxingtuDTO) {
        IPage<HouseHuxingtuVo> page = this.houseHuxingtuService.searchByXML(super.startPage(), houseHuxingtuDTO);
        return super.getTableInfo(page);
    }

    /**
     * 根据id查询详细信息
     * @param id
     * @return
     */
    @GetMapping(value = "/house/huxingtu/detail/{id}")
    public AjaxResult getHuxingtuDetail(@PathVariable(value = "id") int id) {
        HouseHuxingtuVo byId = this.houseHuxingtuService.selectOne(id);
        return AjaxResult.success_data(byId);
    }

    /**
     * 户型图新增
     *
     * @param houseHuxingtu
     * @return
     */
    @PostMapping(value = "/house/huxingtu/add")
    public AjaxResult add(@RequestBody HouseHuxingtu houseHuxingtu) {

        int insert = this.houseHuxingtuService.insert(houseHuxingtu);

        if (insert > 0) {
            return AjaxResult.success("新增成功");
        } else {
            return AjaxResult.error("新增失败");
        }
    }

    /**
     * 户型图修改
     * @param houseHuxingtu
     * @return
     */
    @PostMapping(value = "/house/huxingtu/edit")
    public AjaxResult edit(@RequestBody HouseHuxingtu houseHuxingtu) {

        boolean updateById = this.houseHuxingtuService.updateById(houseHuxingtu);

        if (updateById) {
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 户型图删除
     * @param id
     * @return
     */
    @PostMapping(value = "/house/huxingtu/delete/{id}")
    public AjaxResult delete(@PathVariable(value = "id") Long id) {

        boolean removeById = this.houseHuxingtuService.removeById(id);

        if (removeById) {
            return AjaxResult.success("删除成功");
        } else {
            return AjaxResult.error("删除失败");
        }
    }
}
